﻿using System;
using System.IO;
using System.Text;
using YEA.Infrastructure.Gateway;

namespace YEA.Infrastructure.Gateway.Converter
{
    public static class MessageToStringConverter
    {
        public static string Convert(Message message)
        {
            var content = string.Empty;
            if (message.Properties.ContentType == YEA.Infrastructure.Gateway.Converter.StringToMessageConverter.PLAIN_TEXT)
            {
                var encoding = Encoding.GetEncoding(message.Properties.ContentEncoding ?? "utf-8");
                var ms = new MemoryStream(message.Body);
                var reader = new StreamReader(ms, encoding, false);
                content = reader.ReadToEnd();
            }
            return content;
        }
    }
}
